package cn.xshi.route.publisher.core;

import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

/**
 * @Desc 编码器（自定义Json编码器）
 * @Author 邓纯杰
 * @CreateTime 2021-09-18
 */
@Slf4j
public class JsonMessageEncoder  extends MessageToMessageEncoder<Object> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object obj, List<Object> list) throws Exception {
        String json = JSONObject.toJSONString(obj);
        log.info("发送报文：" + json);
        list.add(json);
    }
}
